import { BaseModel } from '@/common/base/base.model';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { AdminModel } from "@/module/admin/admin.model";
import { UserModel } from "@/module/user/user.model";
import { RoleModel } from "@/module/role/role.model";

@Entity('ADMINUSER_ROLE', {
  synchronize: false,
}) // 管理员或用户与角色的中间表
export class AdminuserRoleModel extends BaseModel {
  @Column({
    comment: '管理员uuid',
    type: 'uuid',
    nullable: true,
  })
  adminUuid: string;
  @ManyToOne(() => AdminModel,{
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'admin_uuid',
    referencedColumnName: 'uuid',
  })
  admin: AdminModel;

  @Column({
    comment: '用户uuid',
    type: 'uuid',
    nullable: true,
  })
  userUuid: string;
  @ManyToOne(() => UserModel,{
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'user_uuid',
    referencedColumnName: 'uuid',
  })
  user: UserModel;

  @Column({
    comment: '角色uuid',
    type: 'uuid',
  })
  roleUuid: string;
  @ManyToOne(() => RoleModel,{
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'role_uuid',
    referencedColumnName: 'uuid',
  })
  role: RoleModel;
}
